<template>
  <div class='search'>
    <f-drawer ref='orderDrawer' :show-footer='false' title='订单详情' width='87%' @visibleChange='visibleChange'>
      <hy-order-details ref='form1' v-if='drawerVisible' style='margin-bottom: 50px' @success='handleSuccess'></hy-order-details>
    </f-drawer>
  </div>
</template>
<script>

import HyOrderDetails from "./hyorder_details"

export default {
  name: "HyOrderDetailsDrawer",
  props: {},
  data() {
    return {
      refs: this.$refs,
      drawerVisible: false,
      isEdit: false,
      title: "",
      columns: [],
      current: "form1",
      formData: {},
      forms: [
        "form1"
      ]
    }
  },
  methods: {
    showDrawer(data) {
      this.isEdit = false
      if (data && data.orderId) {
        this.isEdit = true
        this.formData = data
        this.columns = this.getCol(data)
      } else {
        this.formData = {}
      }
      this.refs["orderDrawer"].show()
      this.tabClick("form1")
    },
    renderTdBackground(record, color) {
      if (record.saleManId) {
        return {
          style: {
            "background-color": color
          }
        }
      }
    },
    getCol(data) {
      let sendType = data.sendType
      let backOrderNo = data.backOrderNo
      return [
        {
          title: "商品名称",
          align: "left",
          ellipsis: true,
          width: "140px",
          dataIndex: "drugsName"
        },
        {
          title: "规格",
          align: "left",
          ellipsis: true,
          length: 30,
          width: "120px",
          dataIndex: "drugsSpec"
        },
        {
          title: "仓库",
          align: "center",
          width: "120px",
          ellipsis: true,
          dataIndex: "storeName"
        },
        {
          title: "类型",
          align: "center",
          width: "80px",
          dataIndex: "drugType",
          scopedSlots: { customRender: "drugType" }
        },
        {
          title: "生产企业",
          align: "center",
          width: "130px",
          ellipsis: true,
          dataIndex: "producersName"
        },
        {
          title: "销售单价",
          align: "center",
          width: "80px",
          dataIndex: "salePrice"
        },
        {
          title: "数量",
          align: "center",
          width: "80px",
          dataIndex: "saleNum"
        },
        {
          title: "已退数量",
          align: "center",
          width: "80px",
          hidden: backOrderNo == "",
          dataIndex: "backNum"
        },
        {
          title: "销售金额",
          align: "center",
          width: "80px",
          needTotal: true,
          dataIndex: "saleAmount"
        },
        {
          title: "资保金应收",
          align: "center",
          width: "90px",
          hidden: sendType != 3,
          dataIndex: "customBond"
        },
        {
          title: "操作",
          align: "center",
          dataIndex: "action",
          width: "100px",
          scopedSlots: { customRender: "action" }
        }
      ]
    },
    visibleChange(drawerVisible) {
      this.drawerVisible = drawerVisible
    },
    handleSuccess() {
      this.$emit("success")
    },
    tabClick(name) {
      this.current = name
      this.$nextTick(() => {
        this.refs[this.current].setData(this.formData)
      })
    }
  },
  computed: {
    drawerTitle: function() {
      return this.title
    }
  },
  created() {
  },
  components: { HyOrderDetails }
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
